import React, { useEffect, useState } from 'react';
import store from "./store";

export default function UseSyncExternalStoreDemo(maxAge) {
  const [num,setNum] = useState(store.getState().count);

  useEffect(()=>{
    store.subscribe(()=>{
      setNum(store.getState().count)
    })
  },[])

  function add(){
    store.dispatch({
      type:"ADD",
      payload:2
    })
  }

  return (
    <div>
      <h1>useSyncExternalStore示例</h1>
      <p>num:{num}</p>
      <input type="button" value="加法" onClick={add} />
    </div>
  )
}